/*
 * Copyright (C) 2012  E-dance Studio Harbin Institute of Technology 
 * Project:campusmobile
 * Author: 初楷博
 * Create Date: 2012-5-23下午02:01:20
 */
package hit.edance.campusmobile.chat.util;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * sharedPreference工具
 * 
 * @Project campusmobile
 * @Package hit.edance.campusmobile.chat.util
 * @Class SharedPreferencesHelper
 * @Date 2012-5-23 下午02:01:20
 * @author 初楷博
 * @version
 * @since
 */
public class SharedPreferencesHelper {

	private final String PREFERENCE_NAME = "campusmobile"; // sharedpreference配置文件名称

	private SharedPreferences mSharedPreferences; // sharedpreference对象

	public SharedPreferencesHelper(Context context) {
		// sharedpreference文件私有
		mSharedPreferences = context.getSharedPreferences(PREFERENCE_NAME,
				Context.MODE_PRIVATE);
	}

	/**
	 * 保存配置信息
	 * 
	 * @param key
	 * @param value
	 */
	public void setValueByKey(String key, String value) {
		mSharedPreferences.edit().putString(key, value).commit();
	}

	/**
	 * 获得配置信息
	 * 
	 * @param key
	 * @param defValue
	 * @return
	 */
	public String getValueByKey(String key, String... defValue) {
		return defValue.length > 0 ? mSharedPreferences.getString(key,
				defValue[0]) : mSharedPreferences.getString(key, "");
	}
}
